package cn.ltgodm.template.web.controller.auth;

import cn.ltgodm.template.common.domain.AjaxResult;
import cn.ltgodm.template.common.utils.RedisCache;
import cn.ltgodm.template.common.utils.StringUtils;
import cn.ltgodm.template.user.domain.param.RegisterParam;
import cn.ltgodm.template.user.domain.param.UserParam;
import cn.ltgodm.template.user.service.impl.RegisterService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ltgodm
 * @date 2024-03-22 09:33:12
 * 用户注册
 */
@RestController
@Tag(name = "用户注册")
@RequestMapping("/auth")
@ApiSupport(author = "ltgodm")
public class RegisterController {
    @Autowired
    private RegisterService registerService;


    @Value("${user.register.enable}")
    private boolean registerEnable;

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public AjaxResult register(@Validated @RequestBody RegisterParam registerParam){
        if (!registerEnable){
            return AjaxResult.error("当前系统没有开启注册功能！");
        }
        int row = registerService.register(registerParam);
        if (row>0) {
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

}
